DAILY_ANALYSIS_CONFIG = {
    'real_time_report': False,
    'interval_type_list': ['day'],
    'day_to_calc': range(0, 60),
    'target_event_id': ['cp_game', 'cp_lottery', 'recharge', 'withdraw', "platform_reward", 'active', 'register',
                        'bind_phone'],
    'values': [
        {
            "value_id": "register_user",
            "target_value": "_user_id",
            "value_name": "注册账号",
            "filter": [
                {'term': {'_event_id': 'register'}}
            ],
            "operation": "cardinality",
            "value_type": "long"
        },
        {
            "value_id": "bind_register_user",
            "target_value": "_user_id",
            "value_name": "注册绑定账号",
            "filter": [
                {'term': {'_event_id': 'bind_phone'}},
                {'term': {'_is_new_user': 1}}
            ],
            "operation": "cardinality",
            "value_type": "long"
        },
        {
            "value_id": "bind_user",
            "target_value": "_user_id",
            "value_name": "绑定账号",
            "filter": [
                {'term': {'_event_id': 'bind_phone'}}
            ],
            "operation": "cardinality",
            "value_type": "long"
        },
        {
            "value_id": "today_login",
            "target_value": "_user_id",
            "value_name": "登录账号",
            "filter": [
                {'term': {'_event_id': 'active'}}
            ],
            "operation": "cardinality",
            "value_type": "long"
        },
        {
            "value_id": "today_ios_login",
            "target_value": "_user_id",
            "value_name": "IOS登录用户",
            "filter": [
                {'term': {'_event_id': 'active'}},
                {'term': {'_chn.keyword': 'ios'}}
            ],
            "operation": "cardinality",
            "value_type": "long"
        },
        {
            "value_id": "today_android_login",
            "target_value": "_user_id",
            "value_name": "android登录用户",
            "filter": [
                {'term': {'_event_id': 'active'}},
            ],
            "not_filter": [
                {'term': {'_chn.keyword': 'ios'}}
            ],
            "operation": "cardinality",
            "value_type": "long"
        },
        {
            "value_id": "recharge_user",
            "target_value": "_user_id",
            "value_name": "充值账号",
            "filter": [
                {'term': {'_event_id': 'recharge'}}
            ],
            "operation": "cardinality",
            "value_type": "long"
        },
        {
            "value_id": "register_recharge_rate",
            "value_name": "注充率",
            "value_expr": "recharge_user / real_active_user",
            "is_percentage": True,
            "fmt": lambda v: float("%.2f" % (v * 100))
        },
        {
            "value_id": "register_bind_rate",
            "value_name": "注绑率",
            "value_expr": "bind_user / real_active_user",
            "is_percentage": True,
            "fmt": lambda v: float("%.2f" % (v * 100))
        },
        {
            "value_id": "recharge_bind_rate",
            "value_name": "绑充率",
            "value_expr": "recharge_user / bind_user",
            "is_percentage": True,
            "fmt": lambda v: float("%.2f" % (v * 100))
        },
        {
            "value_id": "recharge_amount",
            "target_value": "recharge_price",
            "value_name": "累计充值金额",
            "filter": [
                {'term': {'_event_id': 'recharge'}}
            ],
            "value_type": "float"
        },
        {
            "value_id": "new_user_recharge_amount",
            "target_value": "recharge_price",
            "value_name": "新付费账号",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
                {'term': {'_is_new_user': 1}}
            ],
            "value_type": "long",
            "adjust_amount": True
        },
        {
            "value_id": "veteran_user_recharge_amount",
            "target_value": "recharge_price",
            "value_name": "老用户充值",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
                {'term': {'_is_new_user': 0}}
            ],
            "value_type": "float",
            "adjust_amount": True
        },
        {
            "value_id": "online_recharge",
            "target_value": "recharge_price",
            "value_name": "在线充值",
            "filter": [
                {'term': {'_event_id': 'recharge'}}
            ],
            "not_filter": [
                {'terms': {'recharge_recharge_type': ['wechat', 'mf_pay']}}
            ],
            "value_type": "float",
            "adjust_amount": True
        },
        {
            "value_id": "new_user_online_recharge",
            "target_value": "recharge_price",
            "value_name": "新用户在线充值",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
                {'term': {'_is_new_user': 1}}
            ],
            "not_filter": [
                {'terms': {'recharge_recharge_type': ['wechat', 'mf_pay']}}
            ],
            "value_type": "float",
            "adjust_amount": True
        },
        {
            "value_id": "veteran_user_online_recharge",
            "target_value": "recharge_price",
            "value_name": "老用户在线充值",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
                {'term': {'_is_new_user': 0}}
            ],
            "not_filter": [
                {'terms': {'recharge_recharge_type': ['wechat', 'mf_pay']}}
            ],
            "value_type": "float",
            "adjust_amount": True
        },
        {
            "value_id": "agency_recharge",
            "target_value": "recharge_price",
            "value_name": "代理充值",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
                {'terms': {'recharge_recharge_type': ['wechat', 'mf_pay']}}
            ],
            "value_type": "float",
            "adjust_amount": True
        },
        {
            "value_id": "new_user_agency_recharge",
            "target_value": "recharge_price",
            "value_name": "新用户代理充值",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
                {'term': {'_is_new_user': 1}},
                {'terms': {'recharge_recharge_type': ['wechat', 'mf_pay']}}
            ],
            "value_type": "float",
            "adjust_amount": True
        },
        {
            "value_id": "veteran_user_agency_recharge",
            "target_value": "recharge_price",
            "value_name": "老用户代理充值",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
                {'term': {'_is_new_user': 0}},
                {'terms': {'recharge_recharge_type': ['wechat', 'mf_pay']}}
            ],
            "value_type": "float",
            "adjust_amount": True
        },
        {
            "value_id": "recharge_count",
            "target_value": "_user_id",
            "value_name": "充值次数",
            "filter": [
                {'term': {'_event_id': 'recharge'}}
            ],
            "operation": "value_count",
            "value_type": "long"
        },
        {
            "value_id": "online_recharge_count",
            "target_value": "_user_id",
            "value_name": "在线充值次数",
            "filter": [
                {'term': {'_event_id': 'recharge'}}
            ],
            "not_filter": [
                {'terms': {'recharge_recharge_type': ['wechat', 'mf_pay']}}
            ],
            "operation": "value_count",
            "value_type": "long"
        },
        {
            "value_id": "agency_recharge_count",
            "target_value": "_user_id",
            "value_name": "代理充值次数",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
                {'terms': {'recharge_recharge_type': ['wechat', 'mf_pay']}}
            ],
            "operation": "value_count",
            "value_type": "long"
        },
        {
            "value_id": "average_recharge",
            "value_name": "人均充值",
            "value_expr": "recharge_amount /recharge_user",
            "adjust_amount": True
        },
        {
            "value_id": "active_user",
            "target_value": "_user_id",
            "value_name": "登录用户",
            "filter": [
                {'term': {'_event_id': 'active'}}
            ],
            "operation": "cardinality",
            "value_type": "long",
            "hide_result": True
        },
        {
            "value_id": "real_active_user",
            "target_value": "_user_id",
            "value_name": "活跃账号",
            "filter": [
                {"terms": {"_event_id": ["withdraw", "recharge", "cp_game", "cp_lottery", 'active', 'register']}}
            ],
            "operation": "cardinality",
            "value_type": "long",
            "hide_result": True
        },
        {
            "value_id": "recharge_rate",
            "value_name": "付费率",
            "value_expr": "recharge_user / real_active_user",
            "is_percentage": True,
            "fmt": lambda v: float("%.2f" % (v * 100))
        },
        {
            "value_id": "profit",
            "target_value": ["recharge_price", "-", "withdraw_price"],
            "value_name": "财务营收",
            "filter": [
                {'terms': {'_event_id': ['recharge', 'withdraw']}},
            ],
            "value_type": "float",
            "hide_result": True,
            "adjust_amount": True
        },
        {
            "value_id": "average_donate",
            "value_name": "人均贡献",
            "value_expr": "profit / real_active_user",
            "adjust_amount": True
        },
        {
            "value_id": "withdraw_amount",
            "target_value": "withdraw_price",
            "value_name": "提现金额",
            "filter": [
                {'term': {'_event_id': 'withdraw'}}
            ],
            "value_type": "float",
            "adjust_amount": True
        },
        {
            "value_id": "withdraw_user",
            "target_value": "_user_id",
            "value_name": "提现账号",
            "filter": [
                {'term': {'_event_id': 'withdraw'}}
            ],
            "operation": "cardinality",
            "value_type": "long"
        },
        {
            "value_id": "real_active_user",
            "value_name": "活跃账号",
            "value_expr": "real_active_user",
            "value_type": "long"
        },
        {
            "value_id": "profit_recharge_rate",
            "value_name": "利润率",
            "value_expr": "profit / recharge_amount",
            "is_percentage": True,
            "fmt": lambda v: float("%.2f" % (v * 100))
        },
        {
            "value_id": "profit",
            "value_name": "财务营收",
            "value_expr": "profit",
            "adjust_amount": True
        },
        {
            "value_id": "yesterday_stay_2_user",
            "target_value": "_user_id",
            "value_name": "昨日次留",
            "filter": [
                {'term': {'_event_id': 'active'}}
            ],
            "time_range": {
                "_registered_at": [-2, -2],
                "_event_time": [-1, -1]
            },
            "operation": "cardinality",
            "value_type": "long"
        },
        {
            "value_id": "stay_2_user",
            "target_value": "_user_id",
            "value_name": "次日留存",
            "filter": [
                {"term": {"_event_id": "active"}},
                {"term": {"_account_active_days": 1}}
            ],
            "time_range": {
                "_event_time": [1, 1]
            },
            "operation": "cardinality"
        },
        {
            "value_id": "stay_3_user",
            "target_value": "_user_id",
            "value_name": "3日留存",
            "filter": [
                {"term": {"_event_id": "active"}},
                {"term": {"_account_active_days": 2}}
            ],
            "time_range": {
                "_event_time": [2, 2]
            },
            "operation": "cardinality"
        },
        {
            "value_id": "stay_4_user",
            "target_value": "_user_id",
            "value_name": "4日留存",
            "filter": [
                {"term": {"_event_id": "active"}},
                {"term": {"_account_active_days": 3}}
            ],
            "time_range": {
                "_event_time": [3, 3]
            },
            "operation": "cardinality"
        },
        {
            "value_id": "stay_5_device",
            "target_value": "_user_id",
            "value_name": "5日留存",
            "filter": [
                {"term": {"_event_id": "active"}},
                {"term": {"_account_active_days": 4}}
            ],
            "time_range": {
                "_event_time": [4, 4]
            },
            "operation": "cardinality"
        },
        {
            "value_id": "stay_6_user",
            "target_value": "_user_id",
            "value_name": "6日留存",
            "filter": [
                {"term": {"_event_id": "active"}},
                {"term": {"_account_active_days": 5}}
            ],
            "time_range": {
                "_event_time": [5, 5]
            },
            "operation": "cardinality"
        },
        {
            "value_id": "stay_7_user",
            "target_value": "_user_id",
            "value_name": "7日留存",
            "filter": [
                {"term": {"_event_id": "active"}},
                {"term": {"_account_active_days": 6}}
            ],
            "time_range": {
                "_event_time": [6, 6]
            },
            "operation": "cardinality"
        },
        {
            "value_id": "stay_8_user",
            "target_value": "_user_id",
            "value_name": "8日留存",
            "filter": [
                {"term": {"_event_id": "active"}},
                {"term": {"_account_active_days": 7}}
            ],
            "time_range": {
                "_event_time": [7, 7]
            },
            "operation": "cardinality"
        },
        {
            "value_id": "stay_9_user",
            "target_value": "_user_id",
            "value_name": "9日留存",
            "filter": [
                {"term": {"_event_id": "active"}},
                {"term": {"_account_active_days": 8}}
            ],
            "time_range": {
                "_event_time": [8, 8]
            },
            "operation": "cardinality"
        },
        {
            "value_id": "stay_10_user",
            "target_value": "_user_id",
            "value_name": "10日留存",
            "filter": [
                {"term": {"_event_id": "active"}},
                {"term": {"_account_active_days": 9}}
            ],
            "time_range": {
                "_event_time": [9, 9]
            },
            "operation": "cardinality"
        },
        {
            "value_id": "seven_day_agg_recharge",
            "target_value": "recharge_price",
            "value_name": "7日累计付费金额",
            "filter": [
                {"term": {"_event_id": "recharge"}},
            ],
            "time_range": {
                "_event_time": [0, 6]
            },
            "hide_result": True,
            "adjust_amount": True
        },
        {
            "value_id": "seven_days_ltv",
            "value_name": "7日LTV",
            "value_expr": "seven_day_agg_recharge / register_user",
            "adjust_amount": True
        },
        {
            "value_id": "fourteen_day_agg_recharge",
            "target_value": "recharge_price",
            "value_name": "14日累计付费金额",
            "filter": [
                {"term": {"_event_id": "recharge"}},
            ],
            "time_range": {
                "_event_time": [0, 13]
            },
            "hide_result": True,
            "adjust_amount": True
        },
        {
            "value_id": "fourteen_days_ltv",
            "value_name": "14日LTV",
            "value_expr": "fourteen_day_agg_recharge / register_user",
            "adjust_amount": True
        },
        {
            "value_id": "month_agg_recharge",
            "target_value": "recharge_price",
            "value_name": "30日累计付费金额",
            "filter": [
                {"term": {"_event_id": "recharge"}},
            ],
            "time_range": {
                "_event_time": [0, 29]
            },
            "hide_result": True,
            "adjust_amount": True
        },
        {
            "value_id": "month_ltv",
            "value_name": "30日LTV",
            "value_expr": "month_agg_recharge / register_user",
            "adjust_amount": True
        },
        {
            "value_id": "two_months_agg_recharge",
            "target_value": "recharge_price",
            "value_name": "60日累计付费金额",
            "filter": [
                {"term": {"_event_id": "recharge"}},
            ],
            "time_range": {
                "_event_time": [0, 59]
            },
            "hide_result": True,
            "adjust_amount": True
        },
        {
            "value_id": "two_months_ltv",
            "value_name": "60日LTV",
            "value_expr": "two_months_agg_recharge / register_user",
            "adjust_amount": True
        },
        {
            "value_id": "arpu",
            "value_name": "ARPU",
            "value_expr": "recharge_amount / real_active_user",
            "adjust_amount": True
        },
        {
            "value_id": "arppu",
            "value_name": "ARPPU",
            "value_expr": "recharge_amount / recharge_user",
            "adjust_amount": True
        }
    ]
}
